package com.zxbit.uangstore.presenter;

import com.zxbit.uangstore.base.BasePresenter;
import com.zxbit.uangstore.business.CustomConsumer;
import com.zxbit.uangstore.constant.ParamsFactory;
import com.zxbit.uangstore.domain.LoginResponse;
import com.zxbit.uangstore.mvpview.LoginMvpView;
import com.zxbit.uangstore.network.RetrofitManager;

import java.util.HashMap;
import java.util.Map;

import io.reactivex.functions.Consumer;

public class LoginPresenter extends BasePresenter {
    private LoginMvpView mvpView;

    public LoginPresenter(LoginMvpView mvpView) {
        this.mvpView = mvpView;
    }

    public void doUploadAuthCode(String authorizationCode) {
        Map<String, Object> paramsMap = new HashMap<>();
        paramsMap.put("authCode", authorizationCode);
        toSubScribe(req.uploadFaceBookCode(ParamsFactory.getCommonParams(paramsMap)), new CustomConsumer<LoginResponse>() {
            @Override
            protected void processCommonData(LoginResponse loginResponse) {
                mvpView.onGetDataNext(loginResponse);
            }
        }, new Consumer<Throwable>() {
            @Override
            public void accept(Throwable throwable) throws Exception {
                mvpView.onGetDataError(throwable);
            }
        });
    }
}
